package com.baili.service.operater;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baili.dao.operater.OperateDao;
import com.baili.dto.Call;
import com.baili.dto.Check;
import com.baili.dto.ProductOrder;

/** 
 * @author iceX
 * @version 创建时间：2016年3月31日 下午2:53:05 
 * @Name: InspectorServiceImpl.java
 */
@Service
public class OperaterServiceImpl implements OperaterService{

	@Autowired
	private OperateDao operaterDao;

	@Override
	public List getCallLog(ProductOrder productOrder) {
		
		return operaterDao.getCallLog(productOrder);
	}

	@Override
	public List getCallLogById(int id) {
		
		return operaterDao.getCallLogById(id);
	}

	@Override
	public List getEventType() {
		
		return operaterDao.getEventType();
	}

	@Override
	public void insertEventType(Call call) {
		operaterDao.insertEventType(call);
	}

	@Override
	public void updateState(int id, int state) {
		
		operaterDao.updateState(id ,state);
	}
	
	@Override
	public List<Map<String, Object>> getWarning(ProductOrder productOrder) {
		
		return operaterDao.getWarning(productOrder);
	}

	@Override
	public List getFinishWorkYOrN(ProductOrder productOrder) {
		
		List<Map<String,Object>> lst = operaterDao.getFinishWorkYOrN(productOrder);
		
		if(lst != null && lst.size() > 0){
			
			for(Map<String, Object> map : lst){
				
				int notStartedCount = 0;
				
				int alreadyCompletedCount = 0;
				
				productOrder.setScheduleNo(map.get("scheduleNo").toString());
				
				productOrder.setProductCode(map.get("productCode").toString());
				
				List<Map<String,Object>> roundLst = operaterDao.getroundList(productOrder);
				
				for(Map<String, Object> roundMap:roundLst){
					
					String state = roundMap.get("state").toString();
					String kzType = roundMap.get("kzType").toString();
					String stage = roundMap.get("stage").toString();
					
					if(productOrder.getRemarks().equals("开料")){
						
						if((state.equals("1") && kzType.equals("1") && stage.equals("0"))){
								
							notStartedCount = notStartedCount+1;
							
						}else if(state.equals("5") && kzType.equals("1") || kzType.equals("2")){
							
							alreadyCompletedCount = alreadyCompletedCount +1;
						}
						
					}else if(productOrder.getRemarks().equals("制帮")){
						
						if(state.equals("5") && kzType.equals("1")){
								
							notStartedCount = notStartedCount+1;
							
						}else if(state.equals("5") && kzType.equals("2")){
							
							alreadyCompletedCount = alreadyCompletedCount +1;
						}
					}else{
						
						if(state.equals("1")){
								
							notStartedCount = notStartedCount+1;
							
						}else if(state.equals("5")){
							
							alreadyCompletedCount = alreadyCompletedCount +1;
						}
					}
					
//					if((state.equals("1") && kzType.equals("1") && stage.equals("0"))
//							||(state.equals("1") && kzType.equals("0") && stage.equals("1"))
//							||(state.equals("1") && kzType.equals("0") && stage.equals("0"))){
//							
//						notStartedCount = notStartedCount+1;
//						
//					}else if(state.equals("5")){
//						
//						alreadyCompletedCount = alreadyCompletedCount +1;
//					}
				}
				if(roundLst.size() == notStartedCount){
					
					map.put("status", 1);
					
				}else if(roundLst.size() == alreadyCompletedCount){
					
					map.put("status", 3);
					
				}else {
					
					map.put("status", 2);
					
				}
			}
		}
		
		return lst;
	}

	@Override
	public List getRoundDetails(ProductOrder productOrder) {
		
		return operaterDao.getRoundDetails(productOrder);
	}
	@Override
	public List getroundList(ProductOrder productOrder) {
		
		return operaterDao.getroundList(productOrder);
	}
	@Override
	public List getRoundListToSeeDetails(ProductOrder productOrder) {
		
		return operaterDao.getRoundListToSeeDetails(productOrder);
	}
	@Override
	public List getRoundListToSee(ProductOrder productOrder) {
		
		return operaterDao.getRoundListToSee(productOrder);
	}

	@Override
	public List getpicklists(ProductOrder productOrder) {
		
		return operaterDao.getpicklists(productOrder);
	}

	@Override
	public List getdataList(ProductOrder productOrder) {

		return operaterDao.getdataList(productOrder);
	}

	@Override
	public List getCheckSee(ProductOrder productOrder) {

		return operaterDao.getCheckSee(productOrder);
	}
	@Override
	public List getCheckSeeDefectToPicVdo(ProductOrder productOrder){
		
		return operaterDao.getCheckSeeDefectToPicVdo(productOrder);
	}
	@Override
	public List getCheckSeeDefect(ProductOrder productOrder) {
		
		return operaterDao.getCheckSeeDefect(productOrder);
	}

	@Override
	public List getallfinishroundDetails(ProductOrder productOrder) {

		return operaterDao.getallfinishroundDetails(productOrder);
	}

	@Override
	public List getallfinishpicklists(ProductOrder productOrder) {

		return operaterDao.getallfinishpicklists(productOrder);
	}

	@Override
	public List getallfinishdataList(ProductOrder productOrder) {

		return operaterDao.getallfinishdataList(productOrder);
	}

	@Override
	public List getallfinishroundList(ProductOrder productOrder) {

		return operaterDao.getallfinishroundList(productOrder);
	}

	@Override
	public List getallfinishDetails(ProductOrder productOrder) {

		return operaterDao.getallfinishDetails(productOrder);
	}
	@Override
	public List<Map<String,Object>> getProcessNameByProductTeam(ProductOrder productOrder) {
		
		return operaterDao.getProcessNameByProductTeam(productOrder);
	}

	@Override
	public List getNofinishwork() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List getroundDetails(ProductOrder productOrder) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List getallfinishList(ProductOrder productOrder) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void updateOperationState(ProductOrder productOrder){
		
		operaterDao.updateOperationState(productOrder);
	}
	@Override
	public List<Map<String, Object>> checkedAnalysis(ProductOrder productOrder) {
		return operaterDao.checkedAnalysis(productOrder);
	}

	@Override
	public void insertCheck(Check check) {
		
		operaterDao.insertCheck(check);
		
	}
	
	@Override
	public void deleteCheck(Check check) {
		
		operaterDao.deleteCheck(check);
		
	}
	
	public List getFedAnalysis(ProductOrder productOrder){
		
		return operaterDao.getFedAnalysis(productOrder);
	}
	
	@Override
	public List getCallTypeUser(Call call) {
		
		return operaterDao.getCallTypeUser(call);
		
	}
	@Override
	public List getCallTypeByUser(Call call) {
		
		return operaterDao.getCallTypeByUser(call);
		
	}
	@Override
	public List insertCallTypeUser(Call call) {
		
		return operaterDao.insertCallTypeUser(call);
		
	}
	@Override
	public List getProductTeamsByLevel(int teamLevel) {
		
		return operaterDao.getProductTeamsByLevel(teamLevel);
		
	}
	@Override
	public List deleteCallTypeUser(Call call) {
		
		return operaterDao.deleteCallTypeUser(call);
	}
	@Override
	public List getReferenceMaterial(String finishedProductName) {
		
		return operaterDao.getReferenceMaterial(finishedProductName);
	}
	@Override
	public void updateFedAnalysis(Integer id,Integer feed,Integer checkProcess) {
		
		operaterDao.updateFedAnalysis(id,feed,checkProcess);
	}
	@Override
	public List getProductTeamsByProductTeamId(ProductOrder productOrder) {
		
		return operaterDao.getProductTeamsByProductTeamId(productOrder);
	}
}
